package com.itboye.lottery.fragment.gendan;


import android.app.Fragment;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.itboye.lottery.base.BaseFragment;
import com.itboye.lottery.R;
import com.itboye.lottery.adapter.AdapterFragment;
import com.itboye.lottery.bean.HotPeoleDetail;

import java.util.ArrayList;

/**
 * A simple {@link Fragment} subclass.
 * create an instance of this fragment.
 */
public class HongRenOrderListFragment extends BaseFragment {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private String mHotPeopleId;

    private AdapterFragment adapterFragment;
    private int type;
    RecyclerView rv_gendan;
    public int page = 1;

    public HongRenOrderListFragment() {
        // Required empty public constructor
    }

    ArrayList<HotPeoleDetail.PlanInfoEntity> array = new ArrayList<>();

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @return A new instance of fragment GenDanHongRenDetailFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static HongRenOrderListFragment newInstance(int param1, String param2, ArrayList<HotPeoleDetail.PlanInfoEntity> planInfoEntityList) {
        HongRenOrderListFragment fragment = new HongRenOrderListFragment();
        Bundle args = new Bundle();
        args.putInt(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        args.putSerializable("array", planInfoEntityList);
        fragment.setArguments(args);
        return fragment;
    }

    public void setData(ArrayList<HotPeoleDetail.PlanInfoEntity> planInfoEntityList) {
        if (page == 1) {
            array.clear();
        }
        array.addAll(planInfoEntityList);
        refreshUI();
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_gen_dan_hong_ren_detail;
    }

    private void requestHotOrder(String hotPeopleId) {

    }

    public void loadMore() {
        requestHotOrder(mHotPeopleId);
    }

    boolean hasInit = false;

    @Override
    protected void initData() {
        if (!hasInit) {
            array = (ArrayList<HotPeoleDetail.PlanInfoEntity>) getArguments().getSerializable("array");
            rv_gendan.setLayoutManager(new LinearLayoutManager(getActivity()));
            rv_gendan.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
            //消除滑动卡顿现象 ...
            rv_gendan.setNestedScrollingEnabled(false);//限制recyclerview自身滑动特性,滑动全部靠scrollview完成
            refreshUI();
            hasInit = true;
        }
    }

    private void refreshUI() {
        if (adapterFragment == null) {
            adapterFragment = new AdapterFragment(getActivity(), array);
            rv_gendan.setAdapter(adapterFragment);
        } else {
            adapterFragment.notifyDataSetChanged();
        }
        rv_gendan.setHasFixedSize(true);//固定自身size不受adapter变化影响
    }

    @Override
    public void onClick(View view) {

    }
}
